Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
getting error "TypeError: Cannot read properties of null (reading 'useState')" on useState usage react

So I'm trying to use useState in my nextjs app, but as soon as I add in the line of code to initialize useState it throws a popup error with the error message: TypeError: Cannot read properties of null (reading 'useState')

Here is a simplified version of my code:

import { useState } from 'react'

export default function Home() {
    return (
        <div>
            <Transactions />
        </div>
    )
}



const Transactions = () => {

    const [state, setState] = useState('test')
...
}

React/Next versions I'm running:

"next": "12.1.5",
"react": "18.0.0",
"react-dom": "18.0.0"

Screenshot of error from chrome dev tools: Screenshot of error from chrome dev tools

Any thoughts on what's causing this? Thanks

EDIT Very dumb bug on my end, issue was resolved by importing react...

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

So I forked and cloned your github repo and was not able to reproduce the error on my system. One thing I found was in your navBar component you import

import Link from 'next/Link'

which threw me an error until I could change it next/link to lowercase

import Link from 'next/link'

What I would recommend doing is to reinstall react, just with a simple npm command to see if that fixes your problem. If not let me know!

npm uninstall react
npm install react@latest
about 4 years ago · Juan Pablo Isaza Relatório

0

Just define State inside the Home function

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda